<?php
include("inc/head.php");

$TID = $_GET['TID'];
if(!is_numeric($TID))
{
	alert("请选择模板");
}

$FID = $_GET['FID'];
if(is_numeric($FID))
{
	$Field = new Field();
	$Field->getObjById($FID, "FID", "Field");
}

if($Field && $Field->TID != $TID)
{
	$TID = $Field->TID;
}

$Template = new Template();
$Template->getObjById($TID, "TID", "Template");

if($_POST['doPost'] == "true")
{
	$Field = new Field($_POST);
	if(is_numeric($FID))
	{
		$req = $Field->update();
	}
	else
	{
		$req = $Field->add();
	}
		
	if($req)
	{
		new ActionLog(array("LogType"=>"field_sucess","Action"=>"$TID,$req\t{$currAdmin->AID}"));
		alert("sucess","location","fieldList.php?TID=$TID");
	}
	else
	{
		new ActionLog(array("LogType"=>"field_err","Action"=>"$TID,$req\t{$currAdmin->AID}"));
		alert("err","location","fieldList.php?TID=$TID");
	}
	exit;
}
?>
<form method="post">
<input type="hidden" value="true" name="doPost">
<input type="hidden" value="<?php echo $Field->FID; ?>" name="FID">
<input type="hidden" value="<?php echo $TID; ?>" name="TID">

<table width="90%" cellpadding="1" cellspacing="1" class="list-div">
	<tr>
		<th colspan="2" style="text-align:left"> <?php $FID > 0 ? "修改":"新建"; ?>模板域</th>   
    </tr>
	<tr style="font-weight:bold">
		<td width="100">项目</td>
		<td><?php echo $Template->TName; ?></td>
	</tr>
	<tr>
		<td width="100">字段名称</td>
		<td><input type="text" name="FName" value="<?php echo $Field->FName; ?>" class="input-text"/></td>
	</tr>
	<tr>
		<td width="100">字段属性</td>
		<td><select name="FPropty">
		<?php
		$typearr = array('','Title','Content','Channel','SubChannel','Pic','Author');
		foreach($typearr as $stype)
		{
		echo "<option value=\"{$stype}\"";
		if($Field->FPropty == $stype)
			echo " selected=\"selected\"";
		echo ">{$stype}</option>\n";
		}
		?>
		</select>
		</td>
	</tr>
	<tr>
		<td width="100">字段类型</td>
		<td><select name="FType"<?php if(!is_numeric($Field->FID)) echo " onchange=\"chengDepositing(this)\""; ?>>
		<?php
		$typearr = array('Form::TextField', 'Form::TextArea', 'Form::FullTextArea', 'Form::PassWord', 'Form::RadioGroup', 'Form::CheckBoxGroup', 'Form::DropDownList', 'Form::Image', 'Form::CrossPublish', 'Application::SqlResult', 'Application::CrossPublish');
		foreach($typearr as $stype)
		{
		echo "<option value=\"{$stype}\"";
		if($Field->FType == $stype)
			echo " selected=\"selected\"";
		echo ">{$stype}</option>\n";
		}
		?>
		</select>
		<script>
		function chengDepositing(s)
		{
			var dy = document.getElementById('Field_Depositing_Y');
			var dn = document.getElementById('Field_Depositing_N');
			if(s.options[s.selectedIndex].value.indexOf("Application") == 0)
			{
				dn.checked = true;
				dy.checked = false;
			}
			else
			{
				dn.checked = false;
				dy.checked = true;
			}
		}
		</script>
	</td>
	</tr>
	<tr>
		<td width="100">是否入库</td>
		<td><input type="radio" name="Depositing" value="N"<?php if($Field->Depositing == "N")echo " checked='checked'"; ?> id="Field_Depositing_N">否 <input type="radio" name="Depositing" value="Y"<?php if(strtolower($Field->Depositing) == "y" || !$Field->Depositing)echo " checked='checked'"; ?> id="Field_Depositing_Y">是</td>
	</tr>
	<tr>
		<td width="100">索引</td>
		<td><input type="radio" name="FIndex" value=""<?php if($Field->FIndex == "")echo " checked='checked'"; ?>>无 <input type="radio" name="FIndex" value="INDEX"<?php if(strtolower($Field->FIndex) == "index")echo " checked='checked'"; ?>>有<!-- <input type="radio" name="FIndex" value="UNIQUE "<?php if(strtolower($Field->FIndex) == "unique")echo " checked='checked'"; ?>>唯一--></td>
	</tr>
	<tr>
		<td width="100" valign="top">算法</td>
	  <td><textarea name="ProgramCode" cols="100" rows="20"><?php echo htmlspecialchars($Field->ProgramCode); ?></textarea></td>
	</tr>
	<tr>
		<td width="100" valign="top">默认值</td>
	  <td><textarea name="DefaultVal" cols="100" rows="10"><?php echo htmlspecialchars($Field->DefaultVal); ?></textarea></td>
	</tr>
	<tr onclick="s= this.parentNode.childNodes;for(a in s){if(typeof(s[a].style)!='undefined')if(s[a].style.display=='none')s[a].style.display=''}">
	<td colspan="2">高级设置</td>
	</tr>
	<tr style="display:none">
		<td width="100">数据库字段名</td>
		<td><input type="text" name="TFName" value="<?php echo $Field->TFName; ?>" readonly="readonly" class="input-text"/></td>
	</tr>
	<tr style="display:none">
		<td width="100">入库字段类型</td>
		<td><input type="text" name="TFType" value="<?php echo $Field->TFType; ?>" class="input-text"/></td>
	</tr>
	<tr style="display:none">
		<td width="100">入库字段长度</td>
		<td><input type="text" name="FLength" value="<?php echo $Field->FLength; ?>" class="input-text"/></td>
	</tr>
	<tr style="display:none">
		<td width="100">列表顺序</td>
		<td><input type="text" name="ListOrder" value="<?php echo $Field->ListOrder; ?>" class="input-text" /></td>
	</tr>
	<tr style="display:none">
		<td width="100">执行顺序</td>
		<td><input type="text" name="ExecOrder" value="<?php echo $Field->ExecOrder; ?>" class="input-text" /></td>
	</tr>
	<tr style="display:none">
		<td width="100">编辑顺序</td>
		<td><input type="text" name="EditOrder" value="<?php echo $Field->EditOrder; ?>" class="input-text" /></td>
	</tr>
	<tr style="display:none">
		<td width="100">高度</td>
		<td><input type="text" name="Height" value="<?php echo $Field->Height; ?>" class="input-text" /></td>
	</tr>
	<tr style="display:none">
		<td width="100">宽度</td>
		<td><input type="text" name="Width" value="<?php echo $Field->Width; ?>" class="input-text" /></td>
	</tr>
	<tr style="display:none">
		<td width="100" valign="top">配置</td>
	  <td><textarea name="Config" cols="100" rows="10"><?php echo htmlspecialchars($Field->Config); ?></textarea></td>
	</tr>
	<tr>
		<td width="100"></td>
		<td><input type="submit" name="sub" value="提交"> <input type="button" onclick="history.go(-1)" value="返回" /></td>
	</tr>
</table>

</form>
<?php
include("inc/foot.php");
?>
